<?php
//include REPOMATH_ROOT . '/util/DBUtil.class.php';
require_once REPOMATH_ROOT . '/util/DBUtil.class.php';


class User {
	var $db;

	public function User() {
		$this->db = new DBUtil();
	}

	public function Login($username, $password) {
		$rows = $this->db->ExQueryGetArray("select a.*,b.* from tbl_User a,tbl_Role b where Us_user_name = '$username' and a.Us_role_id = b.Ro_id ");
		//echo($rows);

		if ($rows != false) {
			foreach ($rows as $row) {
				if ($row["Us_passw"] == $password) {
					$lifeTime = 900; //seconds 
					session_set_cookie_params($lifeTime);
					session_start();
					$_SESSION["user"] = $row;
					return $row;
				}
			}
		}
		return false;
	}

	public function LogOut() {
		session_start();
		unset ($_SESSION["user"]);
		session_destroy();
	}
}
?>